﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Routing;

namespace ProjectBase.Core.Web
{
    /// <summary>
    ///     Description for button item
    /// </summary>
    public class ButtonItem : IButtonItem
    {
        #region members
        string _buttonName;
        string _formAction;
        RouteValueDictionary _routeValues = new RouteValueDictionary();
        string _text;
        #endregion members

        #region constructor
        public ButtonItem(string buttonName)
        {
            Contract.Requires(buttonName.IsNotEmpty(), " IButtonItem requires not null nor empty property 'ButtonName'. ");
            _buttonName = buttonName;
        }
        #endregion constructor

        #region IButtonItem Members
        /// <summary>
        ///     Unique name which identifies button and therefore MUST be set!
        ///     This property would be used instead of FormAction, Text or TextLocalized - if they are not provided
        /// </summary>
        public virtual string ButtonName
        {
            get { return _buttonName; }
            set { _buttonName = value; }
        }

        /// <summary>
        ///     String key which should be used for Localization.
        ///     This is used if string.IsNullOrEmpty(TextLocalized).
        ///     If the Text property is not provided the ButtonName is used
        /// </summary>
        public virtual string Text
        {
            get
            {
                if (_text.IsEmpty())
                {
                    return ButtonName;
                }
                return _text;
            }
            set { _text = value; }
        }

        /// <summary>
        ///     Already localized and Text for user
        /// </summary>
        public virtual string TextLocalized { get; set; }

        /// <summary>
        ///     Allows to set the FORM attributes 'id' and 'name' for JavaScript handling.
        ///     E.g. the default value for ButtonSubmit is "Constants.WebControls.MainFormId".
        ///     If null or mepty, attributes 'id' and 'name' are not rendered at all.
        /// </summary>
        public virtual string FormIdForJS { get; set; }

        /// <summary>
        ///     If set to true, button is rendered,
        ///     but not working (disabled)
        /// </summary>
        public virtual bool IsDisabled { get; set; }

        /// <summary>
        ///     Allows to append the title attribute with provided value.
        ///     The GetLoclized is called with value as a key
        /// </summary>
        public virtual string Title { get; set; }

        /// <summary>
        ///     1) if FormController exists = 'FormController/FormAction'
        ///     2) FormController is null or empty = 'Model.MasterModel.CurrentController/FormAction'
        ///     3) If FormAction is null or empty - ButtonName is used as the action name
        /// </summary>
        public virtual string FormAction
        {
            get
            {
                if (_formAction.IsEmpty())
                {
                    return ButtonName;
                }
                return _formAction;
            }
            set { _formAction = value; }
        }

        /// <summary>
        ///     Allows to specify the Controller on which is the Action
        ///     which will this button's form target.
        ///     The 'ButtonsWC' webControl will use the Model.MasterModel.ControllerName
        ///     in cases that this instance property FormController remains null or empty
        /// </summary>
        public virtual string FormController { get; set; }

        /// <summary>
        ///     Extend the Form Path with key-pair values.
        ///     If ActionValue.Is(), then is converted into the { id = ActionValue }
        /// </summary>
        public virtual RouteValueDictionary FormRouteValues
        {
            get { return _routeValues; }
            set { _routeValues = value; }
        }

        /// <summary>
        ///     This is the switch for the MasterPage.
        ///     Every FORM tag must be closed. In cases, that the Page Or Control calls the
        ///     CreateForm() operation without its closing pair CloseForm()
        ///     (and therefore sets this property to IsFormTagClosed = true
        ///     MasterPage will (could) try to close this form inside of the div id="divBody"
        /// </summary>
        public virtual bool IsFormTagClosed { get; set; }
        #endregion

        /// <summary>
        ///     Returns the ButtonName
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return ButtonName;
        }
    }
}